<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.onlineMIS.ORM.entity.headQ.finance.FinanceCategory"%>
<%@ page import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>禧乐仓连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>
<script>
var isSelectAll = false;

var dataGrid ;
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	$("#statusSelect").combobox('setValue',-1);
	$("#transferSelect").combobox('setValue',-1);
	$("#belongTo2").combobox('setValue',-1);
	
	function BSkeyDown(e){

		 var ieKey = event.keyCode;

		 if (ieKey==13){
		   if (event.srcElement.id == "searchName"){
			   searchAcct(); 
			   event.returnValue=false;
		   } else
			   event.returnValue=false; 
		 } 
	} 


	document.onkeydown = BSkeyDown;

	var params = $.serializeObject($('#searchForm'));

	dataGrid = $('#dataGrid').datagrid({
		url : 'financeHQJSON!searchFinanceCategory',
		queryParams: params,
		fit : true,
		border : false,
		pagination : false,
		pageSize : 15,
		pageList : [ 15, 30],		
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:true,
		nowrap : false,
		rownumbers : true,
		sortName : 'statusS',
		sortOrder : 'asc',
		rowStyler: function(index,row){
			var style = "";
			if (row.status == 1)
				style += 'color:red;';

			return style;
		},
		columns : [ [ 
		              
		     {
				field : 'itemName',
				title : '账目名字',
				width : 180,
				sortable:true,
				align: 'left',
				order:'desc'
			},{							    	
				field : 'acumulateAmt',
				title : '当前账目',
				width : 100,
				sortable:true,
				align: 'center',
				order:'desc',
				formatter: function (value, row, index){
					return (row.acumulateAmt).toFixed(2);
				}
			}, {
				field : 'initialAmt',
				title : '初始账目',
				sortable:true,
				align: 'center',
				width : 100,
				formatter: function (value, row, index){
					return (row.initialAmt).toFixed(2);
				}
			}, {
				field : 'statusS',
				title : '状态',
				width : 80,				
				align:'center',
				order:'desc'
			},{
				field : 'sort',
				title : '排序',
				width : 80,				
				align:'center',
				order:'desc'
			},{
				field : 'belongTos',
				title : '账目类型',
				width : 90,				
				align:'center',
				order:'desc'
			},{
				field : 'belongTo2',
				title : '账目归属',
				width : 90,				
				align:'center',
				formatter :  function(value, row, index) {
					if(row.id == 0){
						var str = "";
					}else if(row.belongTo2 == <%=FinanceCategory.BELONG_TO_QX%>){
						var str = $.formatString('<button class="button">千禧</button>');
					}else if(row.belongTo2 == <%=FinanceCategory.BELONG_TO_XLC%>){
						var str = $.formatString('<button class="button1">禧乐仓</button>');
					}
					return str;
				}
			}, {
				field : 'transferAccounts',
				title : '支持转账',
				width : 80,
				align:'center'
			}, {
				field : 'createBy',
				title : '创建人',
				width : 100,
				align:'center',
			},{
				field : 'createDate',
				title : '创建时间',
				width : 150,
				align:'center',
			},{
				field : 'comment',
				title : '备注信息',
				width : 120,
				align:'center',
			},{				
				field : 'action',
				title : '更改',
				width : 80,
				align:'center',
			formatter : function(value, row, index) {
				var str = '';
				str += $.formatString('<a href="#" onclick="update(\'{0}\');"><img border="0" src="{1}" title="更改账目信息"/></a>', row.id, '<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/update.png');
				return str;
			   }
		   },{				
			field : 'actionTwo',
			title : '账目流水',
			width : 90,
			align:'center',
		   formatter : function(value, row, index) {
				var str = '';
				var url = "financeHQJSP!cardFlowDetails?formBean.fc.id ="+ row.id;
				str += $.formatString('<a href="#" onclick="addTab7(\'{0}\',\'{1}\');"><img border="0" src="{2}" title="账目流水"/></a>',url, "账目流水", '<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/fund.png');
				return str;
		  	}
		},
		   ]],
		   onLoadSuccess: function(data) {
		        var tr = $(this).datagrid('getPanel').find('div.datagrid-body tr');
		        tr.each(function() {
		            $(this).children('td').children('div').css('height', '30px');
		        });
		        $(this).datagrid('getPanel').find('.datagrid-body .datagrid-cell').css({
		            'display': 'flex',
		            'align-items': 'center'
		        });
		    },
		toolbar : '#toolbar',
	});

});

function add(){
	var params = "";

	$.modalDialog.opener_dataGrid = dataGrid;
	
	$.modalDialog({
		title : "新增账目信息",
		width : 750,
		height : 550,
		modal : false,
		draggable:false,
		href : 'financeHQJSP!editFinanceCategory',
		
	});
}
function update(id){
	var params = "formBean.fc.id=" + id;
	$.modalDialog({
		title : "更新账目信息",
		width : 750,
		height : 550,
		modal : false,
		draggable:false,
		href : 'financeHQJSP!editFinanceCategory?' + params,
		
	});
}
function edit(){
	var rows = dataGrid.datagrid('getSelections');
	if (rows.length == 0){
		parent.$.messager.alert('错误', '请选中一个账目信息再继续操作', 'error');
		return;
	}
	
	var	id = rows[0].id;

	update(id);

}

function searchAcct(){
	dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
}
function cleanSearch(){
	$('#searchForm input').val('');
	dataGrid.datagrid('load', {});
}
function refresh(){
	dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
}

function downloadFinanceCategory(){
	document.searchForm.action="financeHQJSP!downloadFinanceCategory";
	document.searchForm.submit();
}

function downloadFinanceFlow(){
	var params = "";

	$.modalDialog.opener_dataGrid = dataGrid;
	
	$.modalDialog({
		title : "账目流水下载",
		width : 680,
		height : 300,
		modal : false,
		draggable:false,
		href : 'financeHQJSP!preFincaceFlowDownload',
		
	});
}



function cancel(){
	$.modalDialog.handler.dialog('close');
}


function downloadJSFcFlow(){
	document.updateExpenseTypeForm.action="financeHQJSP!downloadFcFlow";
	document.updateExpenseTypeForm.submit();
	cancel();
}

function downloadFcFlow(){
	document.updateExpenseTypeForm.action="financeHQJSP!downloadFcAllFlow";
	document.updateExpenseTypeForm.submit();
	cancel();
}


/**
 * 账目全选或者取消
 */
function selectAll(){
	if(!isSelectAll){
		$("input[name='formBean.ids']").prop("checked",true);
		isSelectAll = true;
	}else{
		$("input[name='formBean.ids']").prop("checked",false);
		isSelectAll = false;
	}
	
}

</script>
</head>
<body>
	
<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'north',border:false" style="height: 90px;">
	<s:form id="searchForm" name="searchForm"		
		theme="simple" method="POST">
		<table width="98%" align="center" class="OuterTable">
			<tr>
				<td>
					<table width="100%" border="0">
						<tr>
							<td height="40" colspan="7">
								<div class="errorAndmes">
									<s:actionerror cssStyle="color:red" />
									<s:actionmessage cssStyle="color:blue" />
								</div>
								<table width="100%" border="0">
									<tr class="PBAOuterTableTitale">
										<td height="35" colspan="9">总部账目管理明细：										
										</td>
									</tr>
									<tr height="30">
											<th width="7%" align="center">账目名字：</th>
											<td width="10%" align="left"><input name="formBean.fc.itemName" id="searchName"  class="easyui-textbox"
													data-options="prompt:'请输入账目名字!'" /></td>
											<td width="4%" align="center"><strong>状态：</strong></td>
											<td width="10%" align="left">
													<s:select cssClass="easyui-combobox" style="width:140px" name="formBean.fc.status" data-options="prompt:'请选择账目状态'"   id="statusSelect" listKey="key" listValue="value" headerKey="-1" headerValue="" list="formBean.fc.statusMap" ></s:select>
													
													</td>
											<td width="7%" align="center"><strong>是否支持转账：</strong></td>
											<td width="12%" align="left">
													<s:select cssClass="easyui-combobox" style="width:160px" name="formBean.fc.isTransferAccounts" data-options="prompt:'请选择是否支持转账'" listKey="key" listValue="value"   headerKey="-1" headerValue="" id="transferSelect" list="formBean.fc.transferMap" ></s:select>
													</td>
											<td width="7%" align="center"><strong>账目归属：</strong></td>
											<td width="12%" align="left">
													<s:select name="formBean.fc.belongTo2" id="belongTo2" cssClass="easyui-combobox" style="width:170px;"
														headerKey="-1" headerValue="" data-options="prompt:'请选择账目归属'"
															list="#{'0':'千禧','1':'禧乐仓'}" listKey="key" listValue="value" />	
											</td>
																							
											<td align="left">
													<!--  
													<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-no'" onclick="cleanSearch();" style="width: 60px">清除</a>
													-->
											</td>		
										</tr> 
								
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</s:form>
	</div>
	<div data-options="region:'center',border:false">
			<table id="dataGrid" style="width:500px;">
			</table>

			<div id="toolbar" style="display: none;">
				<a onclick="searchAcct();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-search',plain:true">搜索账目</a> 
				 
				<a onclick="add();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-add'">添加账目</a> 	
				<a onclick="refresh();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-reload'">刷新</a>
				<a onclick="downloadFinanceCategory();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-print'">下载账目</a>	
					<a onclick="downloadFinanceFlow();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-print'">账目流水下载</a>	
			</div>
		</div>
</div>	
</body>
</html>